﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WCITZ.Controllers
{
    public class PollController : Controller
    {
        //
        // GET: /Poll/

        public string Index()
        {
			var db = new WCITZEntities();

			var result = new List<pollResultEntity>();

			foreach (var table in db.Tables.ToList())
			{
				if (table.Name == Request.Form["tableName"])
				{

					foreach (var player in db.Players.ToList())
					{
						if (player.Table == table.Id)
							result.Add(new pollResultEntity { playerName = player.Name, playerStatus = player.Status, playerResult = player.Result });
					}

					break;
				}
			}
			
			return JsonConvert.SerializeObject(result);
        }

    }

	public class pollResultEntity
	{
		public string playerName { get; set; }
		public int playerStatus { get; set; }

		public int? playerResult { get; set; }
	}
}
